package com.myres.util;


import javax.servlet.http.HttpServletRequest;


import com.myres.model.User;
import com.myres.model.VisitLogView;

public class RequestLog {
	public synchronized static void logRequest(HttpServletRequest arequest){
		   final HttpServletRequest request=arequest;
			User u=(User)request.getSession().getAttribute("user");
			VisitLogView log=new VisitLogView();
			if(u!=null)log.setPerson(u.getEmail());
			else log.setPerson(request.getRemoteAddr());
			log.setIp(IpTool.ip2Long(request.getRemoteAddr()));
			
			log.setPage(request.getRequestURI());
			String referer=request.getHeader("referer");
			if(referer==null) referer=request.getParameter("referer");
			log.setReferer(referer);
			try{
				log.save();
			}catch(Exception e){
				e.printStackTrace();
			}
	   }

}
